import React, { useReducer, useEffect } from 'react'
import { Icon } from 'antd-mobile';
import './getnew.css'
import { reducer, initState, actions, getList } from './reducer'
import { getNew } from '../../../../request/api';
export default function GetNew(props) {
    const [state, dispatch] = useReducer(reducer, initState);
    useEffect(() => {
        getNew().then(res => {
            if (res.code === 200) {
                dispatch(actions.changeList(res.list))
                // console.log(getList(state),'======');
            }
        })
    }, [])
    let arr = getList(state)

    let toDetail = (id) =>{
        console.log(props);
        props.history.push("/detail/id="+id)
    }
    return (
        <div>

            <div className="GetNew_wrap">
                <ul>
                    {
                        arr.map(item => {
                            return <li key={item.id} onClick={()=>toDetail(item.id)}>
                                <img src={item.img} alt="" />
                                <div className="getnew_text">
                                    <div className="get_n_L">
                                        <div className="get_n_price">{item.price}</div>
                                        <div className="get_n_mark_P"><del>{item.market_price}</del></div>
                                    </div>
                                    <div className="get_n_r" >
                                        <Icon type="search" />
                                    </div>
                                </div>

                            </li>
                        })
                    }
                </ul>
            </div>
        </div>
    )
}
